package com.dd.ent.car.common.share;

import com.pp.ent.base.log.MLog;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qzone.QZone;

/**
 * Created by dengqu on 2016/8/12.
 */
public class ShareHelper {
    private final static String TAG = "ShareHelper";

    public enum SharePlatform {
        QQ,
        WEICHAT,
        QQZONE,
        WEIBO
    }

    public static void share(SharePlatform sharePlatform, ShareListener shareListener) {
        Platform platform;
        Platform.ShareParams shareParams = null;
        switch (sharePlatform) {
            case QQZONE:
                platform = ShareSDK.getPlatform(QZone.NAME);
                shareParams = new QZone.ShareParams();
                break;
            default:
                platform = null;
                break;
        }

        execute(platform, shareParams, shareListener);

    }

    private static void execute(Platform platform, Platform.ShareParams shareParams, ShareListener shareListener) {
        platform.setPlatformActionListener(new PlatformActionListener() {
            public void onError(Platform platform, int action, Throwable t) {
                // 操作失败的处理代码
                MLog.debug(TAG, "ShareSDK onError");
            }

            public void onComplete(Platform platform, int action, HashMap<String, Object> res) {
                // 操作成功的处理代码
                MLog.debug(TAG, "ShareSDK onComplete");
            }

            public void onCancel(Platform platform, int action) {
                // 操作取消的处理代码
            }
        });
        ShareInfo shareInfo = shareListener.getShareInfo();
        shareParams.setTitle(shareInfo.title);
        shareParams.setTitleUrl(shareInfo.titleUrl); // 标题的超链接
        shareParams.setText(shareInfo.text);
        shareParams.setImageUrl(shareInfo.imageUrl);
        shareParams.setSite(shareInfo.site);
        shareParams.setSiteUrl(shareInfo.siteUrl);
        platform.share(shareParams);
    }

}
